package com.waa.gulimall.common.validator.group;

import lombok.var;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

public class ListValueConstraintValidator implements ConstraintValidator<ListValue,Integer> {
    private Set<Integer> set = new HashSet<>();
    @Override
    public void initialize(ListValue constraintAnnotation) {
        System.out.println("校驗中");
      int values [] = constraintAnnotation.values();
        if (values.length!=0) {
            for (int value : values) {
               set.add(value);
            }
        }
    }

    @Override  //需要检验的值
    public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
        System.out.println("校驗后");
        return set.contains(value);
    }
}
